import Vue from 'vue'
import VueRouter from "vue-router"

// import cookies from "vue-cookies";
// cookies.set('fileInfoId', to.query.fileInfoId)

// 两个主页面
import Home from '../pages/Home'
import Ucenter2 from '../pages/Ucenter2'
// 登录和注册
import Login from '../pages/login/Login'
import Register from '../pages/login/Register'

import Firectrl from '../pages/fire/Firectrl'
import Peoalarm from '../pages/fire/Peoalarm'
import Edgealarm from '../pages/fire/Edgealarm'
import Aimanage from '../pages/fire/Aimanage'
import Home1 from '../pages/fire/Home1'

// 个人中心
import Usercenter from '../pages/userinfo/Usercenter'
import Showinfo from '../pages/userinfo/Showinfo'
import Infoedit from '../pages/userinfo/Infoedit'
import Changepwd from '../pages/userinfo/Changepwd'
import token from '../pages/userinfo/token'




// 创建并暴露一个路由器
const router= new VueRouter({
    // mode:'history', //去掉路径里面的# 默认为hash模式
    routes:[
        {
            path:'/',
            component:Home,
            meta:{title:'主页1'},
            children:[
                {
                    path:'login',
                    component:Login,
                },
                {
                    path:'register',
                    component:Register,
                },
            ]
        },
        
        {
            path:'/login',
            component:Login,
        },
        // {
        //     path:"/firectrl",
        //     component:Firectrl,
        // },
        // {
        //     path:"/peoalarm",
        //     component:Peoalarm,
        // },
        // {
        //     path:"/edgealarm",
        //     component:Edgealarm,
        // },
        
        {
            path:"/register",
            component:Register,
        },
        {
            path:"/home1",
            component:Home1,
        },
        {
            path:"/ucenter3/:token",
            component:token,
        },
        {
            name:'ucenter2',
            path:"/ucenter2",
            component:Ucenter2,
            meta:{title:'主页',isAuth:true},
            children:[
                {
                    name:'home1',
                    path:'home1',
                    component:Home1
                },
                {
                    name:'aimanage',
                    path:'aimanage',
                    component:Aimanage
                },
                {
                    name:'usercenter',
                    path:'usercenter',
                    component:Usercenter,
                    children:[
                        {
                            path: 'showinfo',
                            name: 'showinfo',
                            component: Showinfo
                          },
                          {
                            path: 'infoedit',
                            name: 'infoedit',
                            component: Infoedit
                          },
                        {
                            name:'changepwd',
                            path:'changepwd',
                            component:Changepwd
                        }
                    ]
                },
            ]
        },
        // {
        //     path: '/space',
        //     name: 'space',
        //     component: Space,
        //     children:[
        //       {
        //         path: 'bokelist',
        //         name: 'bokelist',
        //         component: BokeList,
        //       },
        //       {
        //         path: "changeinfo",
        //         name: 'changeinfo',
        //         component: Changeinfo,
        //       },
        //       {
        //         path: "changepic",
        //         name: "changepic",
        //         component: Changpic
        //       },
        //       {
        //         path: "spaceinfo",
        //         name: "spaceinfo",
        //         component: Spaceinfo,
        //       },
        //       {
        //         path: "wirterboke",
        //         name: "wirterboke",
        //         component: Wirterboke
        //       }
        //     ]
        // }
        
    ]
})

// router.beforeEach((to, from, next) => {
//     // to 将访问哪一个路径
//     // from 代表从哪个路径跳转而来
//     // next 是一个函数,表示放行
//     //   next() 放行 next('/login') 强制跳转
//     if (to.path === '/login'){
//         next()
//     }
//     // 获取token
//     else {
//         // 从本地存储里获取token
//         let token = localStorage.getItem('token');
//         // 判断token是否为空如果为空则跳转到登录页 如果有则放行
//         if (token === null || token === '') {
//           next({path:'/login'});
//         } else {
//           next();
//         }
//       }
// })
// router.beforeEach((to, from, next) => {
//     let isLogin = !!localStorage.eleToken
//     if (to.path === '/login' || to.path === '/register'||to.path=='/ucenter2') {
//       next()
//     } else {
//       isLogin ? next() : next('/login')
//     }
//   })
  
export default router